import platform

import psutil
import wmi
import wx
import wx.xrc


class MyFrame(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"我的计算机", pos=wx.DefaultPosition,
                          size=wx.Size(800, 600), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)

        self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
        self.SetBackgroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW))

        bSizer1 = wx.BoxSizer(wx.VERTICAL)

        bSizer1.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer2 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer2.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText111 = wx.StaticText(self, wx.ID_ANY, u"计算机名称", wx.Point(-1, -1), wx.Size(160, -1), 0)
        self.m_staticText111.Wrap(-1)

        self.m_staticText111.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, wx.EmptyString))

        bSizer2.Add(self.m_staticText111, 0, wx.ALL, 5)

        self.computerName = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(320, -1), 0)
        self.computerName.Wrap(-1)

        self.computerName.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))

        bSizer2.Add(self.computerName, 0, wx.ALL, 5)

        bSizer2.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer1.Add(bSizer2, 1, wx.ALL | wx.EXPAND, 5)

        bSizer3 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer3.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText113 = wx.StaticText(self, wx.ID_ANY, u"计算机操作系统", wx.DefaultPosition, wx.Size(160, -1),
                                             0)
        self.m_staticText113.Wrap(-1)

        self.m_staticText113.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, wx.EmptyString))

        bSizer3.Add(self.m_staticText113, 0, wx.ALL, 5)

        self.computerOS = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(320, -1), 0)
        self.computerOS.Wrap(-1)

        self.computerOS.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))

        bSizer3.Add(self.computerOS, 0, wx.ALL, 5)

        bSizer3.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer1.Add(bSizer3, 1, wx.EXPAND, 5)

        bSizer4 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer4.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText115 = wx.StaticText(self, wx.ID_ANY, u"域名", wx.DefaultPosition, wx.Size(160, -1), 0)
        self.m_staticText115.Wrap(-1)

        self.m_staticText115.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, wx.EmptyString))

        bSizer4.Add(self.m_staticText115, 0, wx.ALL, 5)

        self.DomainName = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(320, -1), 0)
        self.DomainName.Wrap(-1)

        self.DomainName.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))

        bSizer4.Add(self.DomainName, 0, wx.ALL, 5)

        bSizer4.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer1.Add(bSizer4, 1, wx.EXPAND, 5)

        bSizer5 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer5.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText117 = wx.StaticText(self, wx.ID_ANY, u"系统制造商", wx.DefaultPosition, wx.Size(160, -1), 0)
        self.m_staticText117.Wrap(-1)

        self.m_staticText117.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, wx.EmptyString))

        bSizer5.Add(self.m_staticText117, 0, wx.ALL, 5)

        self.systemManufacturer = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(320, -1), 0)
        self.systemManufacturer.Wrap(-1)

        self.systemManufacturer.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))

        bSizer5.Add(self.systemManufacturer, 0, wx.ALL, 5)

        bSizer5.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer1.Add(bSizer5, 1, wx.EXPAND, 5)

        bSizer6 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer6.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText119 = wx.StaticText(self, wx.ID_ANY, u"系统型号", wx.DefaultPosition, wx.Size(160, -1), 0)
        self.m_staticText119.Wrap(-1)

        self.m_staticText119.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, wx.EmptyString))

        bSizer6.Add(self.m_staticText119, 0, wx.ALL, 5)

        self.systemType = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(320, -1), 0)
        self.systemType.Wrap(-1)

        self.systemType.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))

        bSizer6.Add(self.systemType, 0, wx.ALL, 5)

        bSizer6.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer1.Add(bSizer6, 1, wx.EXPAND, 5)

        bSizer7 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer7.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText121 = wx.StaticText(self, wx.ID_ANY, u"处理器数", wx.DefaultPosition, wx.Size(160, -1), 0)
        self.m_staticText121.Wrap(-1)

        self.m_staticText121.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, wx.EmptyString))

        bSizer7.Add(self.m_staticText121, 0, wx.ALL, 5)

        self.processorSum = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(320, -1), 0)
        self.processorSum.Wrap(-1)

        self.processorSum.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))

        bSizer7.Add(self.processorSum, 0, wx.ALL, 5)

        bSizer7.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer1.Add(bSizer7, 1, wx.EXPAND, 5)

        bSizer8 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer8.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText123 = wx.StaticText(self, wx.ID_ANY, u"处理器", wx.DefaultPosition, wx.Size(160, -1), 0)
        self.m_staticText123.Wrap(-1)

        self.m_staticText123.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, wx.EmptyString))

        bSizer8.Add(self.m_staticText123, 0, wx.ALL, 5)

        self.processor = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(320, -1), 0)
        self.processor.Wrap(-1)

        self.processor.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))

        bSizer8.Add(self.processor, 0, wx.ALL, 5)

        bSizer8.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer1.Add(bSizer8, 1, wx.EXPAND, 5)

        bSizer9 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer9.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText125 = wx.StaticText(self, wx.ID_ANY, u"内存", wx.DefaultPosition, wx.Size(160, -1), 0)
        self.m_staticText125.Wrap(-1)

        self.m_staticText125.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, wx.EmptyString))

        bSizer9.Add(self.m_staticText125, 0, wx.ALL, 5)

        self.memory = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(320, -1), 0)
        self.memory.Wrap(-1)

        self.memory.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))

        bSizer9.Add(self.memory, 0, wx.ALL, 5)

        bSizer9.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer1.Add(bSizer9, 1, wx.EXPAND, 5)

        bSizer10 = wx.BoxSizer(wx.HORIZONTAL)

        bSizer10.Add((0, 0), 1, wx.EXPAND, 5)

        self.m_staticText127 = wx.StaticText(self, wx.ID_ANY, u"剩余物理地址", wx.DefaultPosition, wx.Size(160, -1), 0)
        self.m_staticText127.Wrap(-1)

        self.m_staticText127.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD, False, wx.EmptyString))

        bSizer10.Add(self.m_staticText127, 0, wx.ALL, 5)

        self.remainPhysicalAddresses = wx.StaticText(self, wx.ID_ANY, u"MyLabel", wx.DefaultPosition, wx.Size(320, -1),
                                                     0)
        self.remainPhysicalAddresses.Wrap(-1)

        self.remainPhysicalAddresses.SetFont(
            wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, wx.EmptyString))

        bSizer10.Add(self.remainPhysicalAddresses, 0, wx.ALL, 5)

        bSizer10.Add((0, 0), 1, wx.EXPAND, 5)

        bSizer1.Add(bSizer10, 1, wx.EXPAND, 5)

        bSizer1.Add((0, 0), 1, wx.EXPAND, 5)

        self.SetSizer(bSizer1)
        self.Layout()

        self.Centre(wx.BOTH)
        self.updateLabels()

    def updateLabels(self):
        # 计算机名称
        computer_name = platform.node()
        # 计算机操作系统
        systemOS = platform.system()
        c = wmi.WMI()
        # 域名
        domain_name = c.Win32_ComputerSystem()[0].Domain
        # 系统制造商
        system_manufacturer = c.Win32_ComputerSystem()[0].Manufacturer
        # 系统型号
        system_model = c.Win32_ComputerSystem()[0].Model
        # 处理器数量
        processor_count = c.Win32_Processor()[0].NumberOfCores
        # 处理器名称
        processor_name = c.Win32_Processor()[0].Name
        # 内存
        memory = psutil.virtual_memory()
        memory_str = str(round(memory.total / 1024 / 1024, 2)) + "MB"
        memory_remain = str(round(memory.available / 1024 / 1024, 2)) + "MB"

        # 更新标签内容
        self.computerName.SetLabel(computer_name)
        self.computerOS.SetLabel(systemOS)
        self.DomainName.SetLabel(domain_name)
        self.systemManufacturer.SetLabel(system_manufacturer)
        self.systemType.SetLabel(system_model)
        self.processorSum.SetLabel(str(processor_count))
        self.processor.SetLabel(processor_name)
        self.memory.SetLabel(memory_str)
        self.remainPhysicalAddresses.SetLabel(memory_remain)

    def __del__(self):
        pass


app = wx.App(False)
frame = MyFrame(None)
frame.Show(True)
app.MainLoop()